local skill = fk.CreateSkill{
  name = "action__youfutongxiang_skill",
}

Fk:loadTranslationTable{
  ["action__youfutongxiang"] = "有福同享",
  ["action__youfutongxiang_skill"] = "有福同享",
  [":action__youfutongxiang"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：选择一名其他角色，令你于此阶段对自己使用基本牌和普通锦囊牌时可以额外指定其为目标。（不可响应）",
  ["#action__youfutongxiang_skill"] = "选择一名其他角色，令你于此阶段对自己使用基本牌和普通锦囊牌时可以额外指定其为目标",
  ["@@action__youfutongxiang1-phase"] = "有福",
  ["@action__youfutongxiang2-phase"] = "同享",
}


skill:addEffect("cardskill", {
  mute = true,
  name = "action__youfutongxiang",
  prompt = "#action__youfutongxiang_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local to = room:askToChoosePlayers(effect.to, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(effect.to),
      skill_name = self.name,
      cancelable = false,
      prompt = "选择一名角色，令你于此阶段对自己使用基本牌和普通锦囊牌时可以额外指定其为目标",
    })
    if #to > 0 then
      room:addPlayerMark(effect.to, "@@action__youfutongxiang1-phase")
      room:setPlayerMark(to[1], "@action__youfutongxiang2-phase",effect.to.id)
    end
  end,
})


skill:addEffect(fk.AfterCardTargetDeclared, {
  mute = true,
  global = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local to = table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("@action__youfutongxiang2-phase") == player.id end)
    if #to == 0 then return false end
    return target == player and player:getMark("@@action__youfutongxiang1-phase") > 0 and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
    and table.contains(data.tos, player) and not table.contains(data.tos, to)
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, {
      skill_name = self.name,
      prompt = "是否令同享标记数为"..player.id.."的角色也成为此牌目标？",
    }) then
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local to = table.filter(player.room:getAlivePlayers(), function(p) return p:getMark("@action__youfutongxiang2-phase") == player.id end)
    for _, p in ipairs(to) do
      data:addTarget(p)
    end
  end,
})


return skill